package bb.lanxing.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.WindowManager;
import android.widget.NumberPicker;
import android.widget.TextView;
import bb.lanxing.R;

public class HeartRateSelectDialog extends Dialog {
    private NumberPicker categoryPicker;
    String heartrate;
    String[] heartrates;

    public HeartRateSelectDialog(Context context, String[] heartrates) {
        super(context, R.style.SprintItemSelector);
        this.heartrate = "100";
        this.heartrates = heartrates;
        initView();
    }

    private void initView() {
        WindowManager.LayoutParams attributes = getWindow().getAttributes();
        attributes.gravity = Gravity.BOTTOM;
        attributes.width = -1;
        attributes.height = -2;
        setContentView(R.layout.dialog_heart_rate_select);
        this.categoryPicker = (NumberPicker) findViewById(R.id.np_watchface_item_category);
        this.categoryPicker.setMinValue(1);
        this.categoryPicker.setMaxValue(this.heartrates.length);
        this.categoryPicker.setDisplayedValues(this.heartrates);

        ((TextView) findViewById(R.id.tv_sprint_watchface_cancel)).setOnClickListener(view -> HeartRateSelectDialog.this.dismiss());
    }

    public String getSelectHR() {
        String[] strArr;
        NumberPicker numberPicker = this.categoryPicker;
        String selected = "";
        if (numberPicker == null || (strArr = this.heartrates) == null || strArr.length <= 0) {
            selected = "0";
        } else {
            if (numberPicker.getValue() != 0) {
                selected = this.heartrates[this.categoryPicker.getValue() - 1];
            } else {
                selected = this.heartrates[this.categoryPicker.getValue()];
            }
        }

        return selected;
    }

    public void select(int index) {
        NumberPicker numberPicker = this.categoryPicker;
        if (numberPicker != null) {
            numberPicker.setValue(index);
        }
    }
}
